import java.io.*;
import java.net.Socket;

//客户端 ： 数据来自于文本文件，接收服务器反馈
public class TCP_Demo3_client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("192.168.191.1", 8888);
        BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\JavaLearn\\idea\\Code\\JavaSE_Code\\MyNet\\src\\tmp\\orig.txt"));
        BufferedWriter bufferedWriter = new BufferedWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
        String line;
        while((line = bufferedReader.readLine()) != null){
            bufferedWriter.write(line);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }
        socket.shutdownOutput();  //关闭输出流，防止出现忙等现象


        //接收服务器反馈信息
        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String data = reader.readLine();
        System.out.println("The message from server :");
        System.out.println(data);

        socket.close();
        bufferedReader.close();
    }
}
